package com.xueke.crawler.service.createLeafDocRelation;

import com.xueke.crawler.dao.DocRelationMapper;
import com.xueke.crawler.dao.SubjectTreeMapper;
import com.xueke.crawler.model.DocRelation;
import com.xueke.crawler.service.AbstractBaseService;
import com.xueke.crawler.service.Start;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by weibo on 2017/5/13.
 *
 * @author weibo.qin
 * @version 2017/5/13
 */
public abstract class BaseCreateDocRelation extends AbstractBaseService implements Start {
    @Autowired
    protected DocRelationMapper docRelationMapper;

    @Autowired
    protected SubjectTreeMapper subjectTreeMapper;

    protected void saveLessonRelation(int leafId, String docId, String docUrl, Integer pnId, Integer cid, Integer
        level) {
        DocRelation docRelation = new DocRelation();
        docRelation.setDocId(Integer.valueOf(docId));
        docRelation.setLeafId(leafId);
        docRelation.setCid(cid);
        docRelation.setLevel(level);
        try{
            docRelationMapper.insertDocRelation(docRelation);
        }catch (Exception e){
            System.out.println("主键重复 忽略 ");
        }


    }


    protected int parseLevel(String txt) {
        if (txt.contains("储值")) return 3;
        if (txt.contains("高级点")) return 2;
        if (txt.contains("扣点数") || txt.contains("普通点")) return 1;
        return 0;
    }
}
